package yang.yu.sunny.infra;

import yang.yu.sunny.EventBus;

import java.util.Set;

/**
 * Created by yyang on 16/3/24.
 */
public class SyncEventBus implements EventBus {

    private com.google.common.eventbus.EventBus guavaEventBus;

    public SyncEventBus(com.google.common.eventbus.EventBus guavaEventBus) {
        this.guavaEventBus = guavaEventBus;
    }

    public void setEventHandlers(Set<Object> handlers) {
        handlers.forEach(eventHandler -> {
            guavaEventBus.register(eventHandler);
        });
    }

    @Override
    public void register(Object eventHandler) {
        guavaEventBus.register(eventHandler);
    }

    @Override
    public void unregister(Object eventHandler) {
        guavaEventBus.unregister(eventHandler);
    }

    @Override
    public void post(Object event) {
        guavaEventBus.post(event);
    }
}
